// 2025/8/26
// dd爱科学1.0

#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n; cin >> n;
    vector<int> upSeq;

    string str; cin >> str;
    for (int i = 0; i < n; i++)
    {
        if (upSeq.empty() || upSeq.back() <= str[i])
        {
            upSeq.emplace_back(str[i]);
        }
        else
        {
            int left = 0, right = upSeq.size() - 1, mid, aim = right;
            while (left <= right)
            {
                mid = (left + right) >> 1;
                if (upSeq[mid] > str[i])
                {
                    aim = mid;
                    right = mid - 1;
                }
                else
                {
                    left = mid + 1;
                }
            }
            upSeq[aim] = str[i];
        }
    }
    int ans = n - upSeq.size();
    cout << ans << endl;
}